# Maintainer: ImperatorS79 <fevrier.simon@gmail.com>

_realname=nodeeditor
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.8
pkgrel=1
pkgdesc="NodeEditor is conceived as a general-purpose Qt-based library aimed at graph-controlled data processing."
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/paceholder/nodeeditor"
license=("BSD-3")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         $([[ ${CARCH} != i686 ]] && echo \
           "${MINGW_PACKAGE_PREFIX}-qt6-base" || echo \
           "${MINGW_PACKAGE_PREFIX}-qt5-base"))
source=(https://github.com/paceholder/nodeeditor/archive/refs/tags/${pkgver}.tar.gz)
sha256sums=('35a1914c6b884a2a64bd07b0d9db4006cee59f6a11ca07611b6daacaf2d52e06')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  mkdir ${srcdir}/build-${MSYSTEM}-shared && cd ${srcdir}/build-${MSYSTEM}-shared

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      ${extra_config[@]} \
      -DBUILD_TESTING=OFF \
      -DBUILD_SHARED_LIBS=ON \
      ../nodeeditor-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .

  mkdir ${srcdir}/build-${MSYSTEM}-static && cd ${srcdir}/build-${MSYSTEM}-static

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      ${extra_config[@]} \
      -DBUILD_TESTING=OFF \
      -DBUILD_EXAMPLES=OFF \
      -DBUILD_SHARED_LIBS=OFF \
      ../nodeeditor-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}-static"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  cd "${srcdir}/build-${MSYSTEM}-shared"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
